<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>工作审批-云校通</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
</head>
<body ontouchstart style="background: #fff;">
	<div class="weui_tab tab-bottom">
		<div class="weui_tab_bd">
	        <div class="weui_tab kcfd-list1" id="tab4">
	            <div class="weui_navbar">
	                <div class="weui_navbar_item">
	                    	我申请的
	                </div>
	                <div class="weui_navbar_item" id="ccList">
	                    	抄送我的
	                </div>
	                
	            </div>
	            <div class="weui_tab_bd">
	                
		            <div class="weui_panel weui_tab_bd_item qingjia mt0">
			            <div class="weui_panel_bd" id="myApply">
			                
			            </div>
			            <div class="dropload-down">
						    <div class="loadData dropload-hasData">点击加载更多数据...</div>
						</div>
		            </div>
			        
		            <div class="weui_panel weui_tab_bd_item qingjia mt0">
			            <div class="weui_panel_bd" id="ccMy">
			                
			            </div>
			            <div class="dropload-down">
						    <div class="loadData dropload-hasData">点击加载更多数据...</div>
						</div>
		            </div>
	            </div>
	        </div>
	       <div class="addBtnnew" id="addBtnnew">
				<div class="linea"></div>
				<div class="lineb"></div>
	       </div>
		</div>
	</div>
	
	<!--弹窗-->				
	<div class="weui_mask ueureiu weui_mask_visible" style="display: none;z-index:600">
	</div>
	<!--End弹窗-->
	
	<!-- 新增审批 start-->
	<div id="add_div_box" class="weui_tab tab-bottom" style="display:none;z-index: 600;background-color: #f8f8f8;">
		<div class="weui_tab_bd">
	        <div class="weui-header bg-blue"> 
	        	<div class="weui-header-left" id="addBack"> <a class="icon icon-109 f-white">取消</a>  </div>
				<h1 class="weui-header-title"></h1>
			</div>
			<div class="weui_grids index_grids type3">
                <a href="<%=basePath %>/ls/work/approval/overtimeApply/add" class="weui_grid js_grid">
                    <div class="weui_grid_icon">
                        <img src="<%=basePath%>/images/jiabanshenqing@3x.png" alt="加班申请">
                    </div>
                    <p class="weui_grid_label">
                       	 加班申请
                    </p>
                </a>
                <a href="<%=basePath %>/ls/work/approval/schoolBus/add" class="weui_grid js_grid">
                    <div class="weui_grid_icon">
                        <img src="<%=basePath%>/images/xiaocheshenqing@3x.png" alt="校车申请">
                    </div>
                    <p class="weui_grid_label">
                       	 校车申请
                    </p>
                </a>
                <a href="<%=basePath %>/ls/work/approval/teachingGoods/add" class="weui_grid js_grid">
                    <div class="weui_grid_icon">
                        <img src="<%=basePath%>/images/dianjiaowupin@3x.png" alt="电教物品">
                    </div>
                    <p class="weui_grid_label">
                       	 教学用品
                    </p>
                </a>
                <a href="<%=basePath %>/ls/work/approval/copyPaper/add" class="weui_grid js_grid">
                    <div class="weui_grid_icon">
                        <img src="<%=basePath%>/images/fuyinyouyin@3x.png" alt="复印油印">
                    </div>
                    <p class="weui_grid_label">
                        	复印油印
                    </p>
                </a>
                <a href="<%=basePath %>/ls/work/approval/printingPaper/add" class="weui_grid js_grid">
                    <div class="weui_grid_icon">
                        <img src="<%=basePath%>/images/dayinzhi@3x.png" alt="打印纸">
                    </div>
                    <p class="weui_grid_label">
                      	  打印纸
                    </p>
                </a>
                
            </div>
         </div>
    </div>	
	<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
	<script>
		var isLoadccList = false;
		var myPage = 1,myRows = 5,ccPage = 1, ccRows = 5;
		$(function() {
			$('#tab4').tab({
				defaultIndex: 0,
				activeClass: "tab-blue "
			});
			$("#addBtnnew").click(function() {
				$('.ueureiu').show();
				$("#add_div_box").show();
			});
			//取消新增
			$("#addBack").click(function() {
				$('.ueureiu').hide();
				$("#add_div_box").hide();
			});
			$("#ccList").click(function() {
				if(!isLoadccList){
					loadccList();
				}
			})
			$(".dropload-down").on("click", ".dropload-hasData", function() {
				var id = $(this).closest(".weui_tab_bd_item").find(".weui_panel_bd").attr("id");
				var param = {
					page: id == 'myApply' ? myPage : ccPage,
					rows: id == 'myApply' ? myRows : ccRows
				}
				if(id == 'myApply') {
					myPage+=1;
					param.applyerId = "${user.teacher.id}";
				}else {
					ccPage+=1;
					param.ccId = "${user.teacher.id}";
				}
				loadItem(param, id);
			})
			var param = {
				page: myPage,
				rows: myRows,
				applyerId: "${user.teacher.id}"
			}
			myPage+=1;
			loadItem(param,"myApply");
		});
		function loadccList(){
			isLoadccList = true;
			var param = {
				page: ccPage,
				rows: ccRows,
				ccId: "${user.teacher.id}"
			}
			ccPage += 1;
			loadItem(param, "ccMy");
		}
		function loadItem(param, id) {
			$.ajax({
				url: basePath + '/ls/work/approval/page/query',
				type: 'post',
				dataType: 'json',
				data: param,
				success: function(data) {
					var html = "";
					if(data.data.rows.length == 0 || param.page*param.rows >= data.data.total) {// 如果没有数据
	            		 $("#" + id).closest(".weui_tab_bd_item").find('.loadData').removeClass("dropload-hasData").addClass("dropload-noData").html("没有更多数据了");
	                }
					for(var i in data.data.rows) {
						var itm = data.data.rows[i];
						html += '<div class="weui_media_box weui_media_appmsg border-bottom1">\
		                    <div class="weui_media_hd">\
		                        <img class="weui_media_appmsg_thumb circle" src="${config.imgUrl}${user.teacher.headImgUrl}" alt="">\
		                    </div>\
		                    <div class="weui_media_bd"><a href="<%=basePath%>/ls/work/approval/detail/'+itm.id+'" style="display: block;">\
		                        <h4 class="weui_media_title"> <span class="f-gray f14 fr">'+getDateDiff((itm.approvalTime == null ? itm.applyTime : itm.approvalTime), "yyyy/MM/dd")+'</span>'+itm.approvalTypeText+'</h4>\
		                        <div class="weui_media_desc f-grayf9 mt10">';
		                    html += '<p class="'+(itm.approvalStatus == '000' ? 'f-green2':'f-yellow2')+'">'+itm.approvalStatusText+'</p></div></a>';
		                    if(itm.approvalStatus == '001' && (new Date().getTime() - itm.applyTime)/1000/60/60 < 2) {
		                    	html += '<div><p><button onclick="revoked('+itm.id+')" class="weui_btn weui_btn_mini bg-red">撤销</button></p>';
		                    }
		                    html += '</div></div></div>';
					}
					$("#" + id).append(html);
				}
			});
		}
		function revoked(applyId) {
			$.confirm("您确定要撤销审批申请吗?","", function() {
				$.ajax({
					url: basePath + '/ls/work/approval/revoked',
					type: 'post',
					dataType: 'json',
					data: {
						applyId: applyId
					},
					success: function(data) {
						if(data.code == '000') {
							$.toast("撤销成功");
						}else {
							$.toast(data.msg, "cancel");
						}
						setTimeout(function() {
	            			window.location.href = window.location.href+"?v="+new Date().getTime();
	            		}, 1000);
					},
		            error: function(xhr, type){
		            	$.toptips("系统异常");
		            }
				});
            }, function() {
            });
		}
	</script>
</body>
</html>